<template>
  <div id="circleManageTop">
    <h1 class="con-right-title">
      圈子管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="圈子名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输入关键词搜索"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item label="开启状态" prop="circleStatus">
          <el-select v-model="formInline.circleStatus" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in circleStatusList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-select
            class="long-input"
            v-model="formInline.sort"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in sortList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'circleManageTop',
  msg: '圈子管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          circleStatus: '', // 圈子状态
          name: '', // 圈子名称
          sort: '', // 排序
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      circleStatusList: [{ dictLabel: '全部', dictValue: '' }], // 圈子状态
      sortList: [], //排序
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getattributeList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 获取数据状态 */
    async getattributeList() {
      // 圈子状态
      let data = await sysNormalDisable('circle_status', 'circleStatus')
      this.circleStatusList = this.circleStatusList.concat(data)
      //排序
      this.sortList = await sysNormalDisable('circle_sort')
      //触发获取列表
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#circleManageTop {
  .el-input.el-input--suffix {
    .el-input__inner {
      padding-right: 25px !important;
    }
  }
  .long-input {
    .el-input.el-input--suffix {
      width: 200px !important;
    }
  }
}
</style>
